import { reactive } from 'vue'
import {
  addVehicleBringGoods,
  getVehicleBringGoodsDataForm,
  updateVehicleBringGoods
} from '@/api/warehouse/vehicle-bring-goods'
export function useDetail(getFormValues: Function) {
  const status = reactive({
    saving: false,
    loading: false
  })

  const createOrUpdate = async () => {
    const values = getFormValues()
    if (status.saving) return false
    status.saving = true
    try {
      values?.code ? await updateVehicleBringGoods(values.code, values) : await addVehicleBringGoods(values)
      status.saving = false
      return true
    } catch (err) {
      status.saving = false
      return false
    }
  }

  // 根据编码获取产品详情
  const getVehicleBringForm = async (code: string) => {
    return getVehicleBringGoodsDataForm(code)
  }

  return {
    status,
    createOrUpdate,
    getVehicleBringForm
  }
}
